/*
 * Logger.cpp
 *
 *  Created on: 05-08-2011
 *      Author: cristian
 */

#include "Logger.h"

Logger::Logger() {

}

Logger::~Logger() {

}

void Logger::hal_trace(const char* component, int color, const char* function,
		const char* file, int line, const char* format, ...)
		{
			char *color_function = new char;
			char *color_fileline = new char;

			va_list args;
			struct timeval tv;
			struct timezone tz;

			gettimeofday(&tv, &tz);

			switch(color) {

				case TRACE_CORE:
				strcpy(color_function ,ANSI_YELLOW);
				strcpy(color_fileline , ANSI_WHITE);
				break;
				case TRACE_PLUGIN:
				strcpy(color_function , ANSI_BLUE);
				strcpy(color_fileline ,ANSI_WHITE);
				break;
			}
			va_start( args, format );
			printf("~ %s%2i.%i%s %s%s[%s%s%s%s%s|%s:%i%s] %s%s():%s ",
					ANSI_CYAN, (int) (tv.tv_sec - Logger::init_time), (int) tv.tv_usec, ANSI_RESET,
		           ANSI_MAGENTA, ANSI_BOLD,
		           ANSI_RESET, ANSI_BOLD, ANSI_GREEN, component, color_fileline, file,
		           line, ANSI_MAGENTA,
		           color_function, function, ANSI_RED);
		    	    vprintf(format, args );
		    	    va_end(args);
		    printf("%s\n", ANSI_RESET);
		    fflush(stdout);
}
